package com.yzm;

import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        Random random = new Random();
        Scanner sc = new Scanner(System.in);
        System.out.println("输入exit退出,输入任意字符开始");
        while (!sc.next().equals("exit")) {
            System.out.print("请输入数据量个数:");
            int n = sc.nextInt();
            int[] arr1 = new int[n];
            int[] arr2 = new int[n];
            int[] arr3 = new int[n];
            int[] arr4 = new int[n];
            int[] arr5 = new int[n];
            int[] arr6 = new int[n];
            int[] arr7 = new int[n];
            int[] temp = new int[arr6.length];
            for (int i = 0; i < n; i++) {
                int x = random.nextInt(100);
                arr1[i] = x;
                arr2[i] = x;
                arr3[i] = x;
                arr4[i] = x;
                arr5[i] = x;
                arr6[i] = x;
                arr7[i] = x;
            }
            System.out.println("原数组是:" + Arrays.toString(arr1));
            long start1 = System.currentTimeMillis();
            SortDemo.shellSort(arr1);
            long end1 = System.currentTimeMillis();
            System.out.println("希尔排序用时" + (end1 - start1) + "ms");
            long start2 = System.currentTimeMillis();
            SortDemo.insertSort(arr2);
            long end2 = System.currentTimeMillis();
            System.out.println("插入排序用时" + (end2 - start2) + "ms");
            long start3 = System.currentTimeMillis();
            SortDemo.bubbleSort(arr3);
            long end3 = System.currentTimeMillis();
            System.out.println("冒泡排序用时" + (end3 - start3) + "ms");
            long start4 = System.currentTimeMillis();
            SortDemo.choiceSort(arr4);
            long end4 = System.currentTimeMillis();
            System.out.println("选择排序用时" + (end4 - start4) + "ms");
            long start5 = System.currentTimeMillis();
            SortDemo.heapSort(arr5);
            long end5 = System.currentTimeMillis();
            System.out.println("堆排序用时" + (end5 - start5) + "ms");
            long start6 = System.currentTimeMillis();
            SortDemo.mergeSort(arr6, 0, arr6.length - 1, temp);
            long end6 = System.currentTimeMillis();
            System.out.println("归并排序后:" + Arrays.toString(arr6));
            System.out.println("归并排序用时" + (end6 - start6) + "ms");
            long start7 = System.currentTimeMillis();
            SortDemo.quickSort(arr7,0,arr7.length-1);
            long end7 = System.currentTimeMillis();
            System.out.println("归并排序后:" + Arrays.toString(arr7));
            System.out.println("快速排序用时" + (end7 - start7) + "ms");
        }
    }
}
